<template>
  <div>
    <div class="bg-white grid-content">
      <div style="overflow: hidden; ">
        <div class="mytitle"><svg-icon icon-class="yjbb" class="myIcon" /> 水源井统计数据审核</div>
      </div>
      <!-- 表格 -->
      <el-table :data="tableData">
        <el-table-column type="index" label="序号" :index="indexMethod">
        </el-table-column>
        <el-table-column align="center" prop="syjmc" label="水源井名称" width="100px">
        </el-table-column>

        <el-table-column align="center" label="基础描述">
          <el-table-column align="center" prop="ssdw" label="所属单位">
          </el-table-column>
          <el-table-column align="center" prop="tcrq" label="投产日期" width="100px">
          </el-table-column>
          <el-table-column align="center" prop="shejicsl" label="设计产水量（10⁴m³/d）" width="110px">
            <!-- <el-table-column align="center" label="（10⁴m³/d）">
          </el-table-column> -->
          </el-table-column>
          <el-table-column align="center" prop="shijicsl" label="实际产水量（10⁴m³/d）" width="110px">
          </el-table-column>
          <el-table-column align="center" prop="ssdxsy" label="所属地下水源">
          </el-table-column>
          <el-table-column align="center" prop="qsddbz1" label="取水地点备注">
          </el-table-column>
          <el-table-column align="center" prop="dxjsw" label="地下静水位（m）">
          </el-table-column>
          <el-table-column align="center" prop="qsdd" label="取水地点">
          </el-table-column>
          <el-table-column align="center" prop="qsddbz2" label="取水地点备注">
          </el-table-column>
          <el-table-column align="center" prop="yt" label="用途">
          </el-table-column>
        </el-table-column>

        <el-table-column align="center" label="井属性">
          <el-table-column align="center" prop="kccw" label="开采层位">
          </el-table-column>
          <el-table-column align="center" prop="zzbj" label="钻凿背景">
          </el-table-column>
          <el-table-column align="center" prop="bx" label="泵型">
          </el-table-column>
          <el-table-column align="center" prop="bpl" label="泵排量">
          </el-table-column>
          <el-table-column align="center" prop="djxh" label="电机型号">
          </el-table-column>
          <el-table-column align="center" prop="sccj" label="生产厂家">
          </el-table-column>
          <el-table-column align="center" prop="qszlqsj" label="取水证领取时间">
          </el-table-column>
          <el-table-column align="center" prop="shejijs" label="设计井深（m）">
          </el-table-column>
          <el-table-column align="center" prop="shijijs" label="实际井深（m）">
          </el-table-column>
          <el-table-column align="center" prop="jj" label="井径（m）">
          </el-table-column>
          <el-table-column align="center" prop="sjzt" label="水井状态">
          </el-table-column>
          <el-table-column align="center" prop="xjcs" label="修井次数（次）">
          </el-table-column>
        </el-table-column>

        <el-table-column align="center" label="井房">
          <el-table-column align="center" prop="jfc" label="井房长（m）">
          </el-table-column>
          <el-table-column align="center" prop="jfk" label="井房宽（m）">
          </el-table-column>
          <el-table-column align="center" prop="jfg" label="井房高（m）">
          </el-table-column>
        </el-table-column>

        <el-table-column align="center" label="经纬度">
          <el-table-column align="center" prop="jwdDj" label="经度">
          </el-table-column>
          <el-table-column align="center" prop="jwdBw" label="纬度">
          </el-table-column>
        </el-table-column>


        <el-table-column align="center" label="计量">
          <el-table-column align="center" prop="jlJlssxh" label="计量设施型号">
          </el-table-column>
          <el-table-column align="center" prop="jlJlsb" label="计量设备（设施）出厂序列号" width="120px">
          </el-table-column>
          <el-table-column align="center" prop="jlJlssazjyhgrq" label="计量设施安装检验合格日期" width="110px">
          </el-table-column>
          <el-table-column align="center" prop="jlSblx" label="水表类型">
          </el-table-column>
        </el-table-column>

        <el-table-column align="center" fixed="right" prop="approveStatus" label="审核状态">
          <template slot-scope="scope">
            <el-tag
            :type="
              scope.row.approveStatus == '2'
              ?'success'
              :scope.row.approveStatus == '1'
                ? 'warning'
                : scope.row.approveStatus == '0'
                  ? 'info'
                  : 'danger'"
              disable-transitions>{{
              scope.row.approveStatus == '2'
              ?'已通过'
              :scope.row.approveStatus == '1'
                ? '未审核'
                : scope.row.approveStatus == '0'
                  ? '未提交'
                  : '未通过'
            }}</el-tag>
          </template>
        </el-table-column>

        <el-table-column align="center" fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row, 'check')" type="text">查看</el-button>
            <el-button @click="handleClick(scope.row, 'edit')" type="text">审核</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页器 -->
      <el-pagination align='right'
          background
          @size-change="handleSizeChange" 
          @current-change="handleCurrentChange" 
          :current-page="pageNo"
          :page-sizes="[5,10, 20, 30, 40, 50]" 
          :page-size="pageSize" 
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
    </div>

    <!-- 弹出框 -->
    <el-dialog :title="myDialogTitle" :visible.sync="dialogFormVisible" :before-close="handleClose" :custom-class="saveAsDialog">

      <el-form v-show="ischeck" :inline="true" :model="syjForm" class="demo-form-inline" :rules="rules" ref="syjForm" :disabled="isInput" label-position="left" label-width="190px" >
        <!-- <el-divider content-position="left">基础信息</el-divider> -->
        <el-row>
          <el-col :span="12">
            <el-form-item label-position="left" label-width="180px" label="水源井名称:" prop="syjmc">
              <el-input v-model="syjForm.syjmc" placeholder="请输入水源井名称"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        

        <el-divider content-position="left">基础描述</el-divider>

        <el-row>
          <el-col :span="12">
            <el-form-item label="所属单位:" prop="ssdw">
              <el-input v-model="syjForm.ssdw" placeholder="请输入所属单位"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="投产日期:" prop="tcrq">
              <el-date-picker v-model="syjForm.tcrq" align="right" type="date" placeholder="请选择日期" value-format="yyyy-MM-dd" :picker-options="pickerOptions">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="设计产水量（10⁴m³/d）:">
              <el-input v-model="syjForm.shejicsl" placeholder="请输入设计产水量"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际产水量（10⁴m³/d）:">
              <el-input v-model="syjForm.shijicsl" placeholder="请输入实际产水量"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属地下水源:">
              <el-input v-model="syjForm.ssdxsy" placeholder="请输入所属地下水源"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="取水地点备注:">
              <el-input v-model="syjForm.qsddbz1" placeholder="请输入取水地点备注"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="地下静水位:">
              <el-input v-model="syjForm.dxjsw" placeholder="请输入地下静水位"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="取水地点:">
              <el-input v-model="syjForm.qsdd" placeholder="请输入取水地点"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="取水地点备注:">
              <el-input v-model="syjForm.qsddbz2" placeholder="请输入取水地点备注"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用途:">
              <el-input v-model="syjForm.yt" placeholder="请输入用途"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">井属性</el-divider>

        <el-row>
          <el-col :span="12">
            <el-form-item label="开采层位:">
              <el-input v-model="syjForm.kccw" placeholder="请输入开采层位"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="钻凿背景:">
              <el-input v-model="syjForm.zzbj" placeholder="请输入钻凿背景"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="泵型:">
              <el-input v-model="syjForm.bx" placeholder="请输入泵型"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="泵排量:">
              <el-input v-model="syjForm.bpl" placeholder="请输入泵排量"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="电机型号:">
              <el-input v-model="syjForm.djxh" placeholder="请输入电机型号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产厂家:">
              <el-input v-model="syjForm.sccj" placeholder="请输入生产厂家"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="取水证领取时间:">
              <el-date-picker v-model="syjForm.qszlqsj" align="right" type="date" placeholder="请选择日期" value-format="yyyy-MM-dd" :picker-options="pickerOptions">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设计井深:">
              <el-input v-model="syjForm.shejijs" placeholder="请输入设计井深"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="实际井深:">
              <el-input v-model="syjForm.shijijs" placeholder="请输入实际井深"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="井径:">
              <el-input v-model="syjForm.jj" placeholder="请输入井径"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="水井状态:">
              <el-input v-model="syjForm.sjzt" placeholder="请输入水井状态"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="修井次数:">
              <el-input v-model="syjForm.xjcs" placeholder="请输入修井次数"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">井房</el-divider>

        <el-row>
          <el-col :span="8">
            <el-form-item label="井房长:">
              <el-input v-model="syjForm.jfc" placeholder="请输入井房长"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="井房宽:">
              <el-input v-model="syjForm.jfk" placeholder="请输入井房宽"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="井房高:">
              <el-input v-model="syjForm.jfg" placeholder="请输入井房高"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">经纬度</el-divider>

        <el-row>
          <el-col :span="12">
            <el-form-item label="经度:">
              <el-input v-model="syjForm.jwdDj" placeholder="请输入经度"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="纬度:">
              <el-input v-model="syjForm.jwdBw" placeholder="请输入纬度"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">计量</el-divider>

        <el-row>
          <el-col :span="12">
            <el-form-item label="计量设施型号:">
              <el-input v-model="syjForm.jlJlssxh" placeholder="请输入计量设施型号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计量设备出厂序列号:">
              <el-input v-model="syjForm.jlJlsb" placeholder="请输入计量设备出厂序列号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计量设施安装检验合格日期:">
              <el-input v-model="syjForm.jlJlssazjyhgrq" placeholder="请输入计量设施安装检验合格日期"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="水表类型:">
              <el-input v-model="syjForm.jlSblx" placeholder="请输入水表类型"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>

      <el-form v-show="!ischeck" :inline="true" :model="syjForm" class="demo-form-inline" ref="syjForm" label-position="left" label-width="80px">
        <el-form-item label="审核:" >
          <el-select v-model="syjForm.approveStatus" placeholder="请选择审核状态">
            <!-- syjForm.approveStatus=='0'? syjForm.approveStatus == '未审核':syjForm.approveStatus=='1'?syjForm.approveStatus == '通过':syjForm.approveStatus == '不通过' -->
            <el-option label="未审核" value="1"></el-option>
            <el-option label="通过" value="2"></el-option>
            <el-option label="不通过" value="3"></el-option>
          </el-select>
        </el-form-item>

        <el-row>
            <el-form-item label="审核备注:">
              <el-input v-model="syjForm.approveBz" placeholder="请输入审核备注"></el-input>
            </el-form-item>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer" v-show="!ischeck">
        <el-button @click="close('syjForm')">取 消</el-button>
        <el-button type="primary" @click="submitForm('syjForm')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import syjApi from '@/api/sjtb/scgl/syjtjb';

export default {
  data() {
    return {
      pageNo: 1, //当前页码
      pageSize: 10, //每页显示数量
      total: 0, //总数量
      // table数据
      tableData: [],
      //当前页码
      currentPage: 1,
      //表单填报的数据
      syjForm: {
        id:'',
        approveStatus:'',//审核状态
        approveBz:'',//审核备注
        rq:'',//填报日期
        syjmc: '',//水源井名称
        ssdw: '',//所属单位
        tcrq: '',//投产日期
        shejicsl: '',//设计产水量
        shijicsl: '',//实际产水量
        ssdxsy: '',//所属地下水源
        qsddbz1: '',//取水地点备注1
        dxjsw: '',//地下静水位
        qsdd: '',//取水地点
        qsddbz2: '',//取水地点备注2
        yt: '',//用途（生产或民用）
        kccw: '',//开采层位
        zzbj: '',//钻凿背景
        bx: '',//泵型
        bpl: '',//泵排量
        djxh: '',//电机型号
        sccj: '',//生产厂家
        qszlqsj: '',//取水证领取时间
        shejijs: '',//设计井深
        shijijs: '',//实际井深
        jj: '',//井径
        sjzt: '',//水井状态
        xjcs: '',//修井次数
        jfc: '',//井房长
        jfk: '',//井房宽handleClose
        jfg: '',//井房高
        jwdDj: '',//经纬度-东经
        jwdBw: '',//经纬度-北纬
        jlJlssxh: '',//计量设施型号
        jlJlsb: '',//计量设备（设施）出厂序列号
        jlJlssazjyhgrq: '',//计量设施安装检验合格日期
        jlSblx: '',//水表类型（机械或电子）
      },
      //验证规则
      rules: {
        syjmc: [
          { required: true, message: '请输入水源井名称', trigger: 'blur' },
        ],
        ssdw: [
          { required: true, message: '请输入所属单位', trigger: 'blur' }
        ],
        tcrq: [
          { required: true, message: '请选择日期', trigger: 'change' }
        ],
      },
      //时间快捷选择
      pickerOptions: {
        // disabledDate(time) {
        //   return time.getTime() > Date.now();
        // },
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周前',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      },
      //获取当前日期
      currentTime:'',
      //
      saveAsDialog:'',
      //编辑框是否显示
      dialogFormVisible: false,
      //弹出框是否是查看
      ischeck: false,
      //控制查看时不可更改数据
      isInput:false,
      //弹出框标题
      myDialogTitle: '',
    }
  },
  created(){
    this.search();
  },
  mounted(){
    this.filterTime();
    // this.initDate();
  },
  // computed:{
  //   isBetterToStr() {
  //     return this.syjForm.approveStatus.toString()
  //   }
  // },
  methods: {
    /**
    * 查询列表
    */
    async search() {
      // this.pageNo = pageNo; //当前页码
      // this.pageSize = pageSize; //每页显示数量
      //发送查询请求
      let res = await syjApi.getSyjList({pageNo:this.pageNo,pageSize:this.pageSize,approveStatus:0});
      //判断是否成功
      if(res.success){
        console.log(res.data);
        //赋值
        this.tableData = res.data.records;
        //总数量
        this.total = res.data.total;
      }
    },
    onSubmit() {
      console.log('submit!');
    },
    //关闭对话框
    handleClose(done) {      
      // 清空表单
      // this.$refs['syjForm'].resetFields();
      // 清空表单校验，避免再次进来会出现上次校验的记录
      this.$refs['syjForm'].clearValidate()
      done()
      
    },
      // 弹框关闭触发
    close(formName) {
      this.dialogFormVisible = false;
      // 清空表单校验，避免再次进来会出现上次校验的记录
      this.$refs[formName].clearValidate()
    },

    submitForm(formName) {
      //表单验证
      this.$refs[formName].validate(async (valid) => {
          if (valid) {
              let res = null;
              console.log(this.syjForm.id+"111")
              //判断菜单ID是否为空
              if (this.syjForm.id === '') {
                this.syjForm.rq = this.currentTime;
                  //发送添加请求
                  res = await syjApi.addSyj(this.syjForm);
              } else {
                  //发送审核请求
                  console.log(334345)
                  res = await syjApi.updateSyj(this.syjForm);
              }
              console.log(res)
              //判断是否成功
              if (res.success) {
                  // this.$message.success(res.message);
                  this.$message({ message: '修改审核状态成功！', type: 'success' });
                  //刷新
                  this.search();
                  //关闭窗口
                  this.dialogFormVisible = false;
              } else {
                console.log(res)
                  this.$message.error(res.message);
              }
          }
      })
    },
    handleClick(row, handle) {
      // console.log(row.approveStatus);
      this.dialogFormVisible = true;
      if (handle == 'check') {
        this.myDialogTitle = '水源井统计'
        this.saveAsDialog = 'saveAsDialog1'
        this.ischeck = true
        this.isInput = true;// 1.表单禁用
        // this.syjForm = row
        this.$objCopy(row, this.syjForm);//把当前要编辑的数据复制到数据域，给表单回显
        this.$message({ message: '成功打开', type: 'success' });
      } else if (handle == 'edit') {
          if(row.approveStatus!=2){
            this.myDialogTitle = '水源井统计审核'
            this.saveAsDialog = 'saveAsDialog2'
            this.ischeck = false  
            this.isInput = false     
            this.$objCopy(row, this.syjForm);//把当前要编辑的数据复制到数据域，给表单回显  
            this.syjForm.approveStatus = row.approveStatus.toString()
          }else {
            this.dialogFormVisible = false;
            this.$message({ message: '已通过不可再审核！', type: 'error' });
          }
        }
    },
    /*** 当每页数量发生变化时触发该事件 */
    handleSizeChange(size) {
      console.log(size);
      this.pageSize = size;
      //将每页显示的数量交给成员变量
      this.search(this.pageNo, size);
    },
    /*** 当页码发生变化时触发该事件 */
    handleCurrentChange(page) {
      console.log(page);
      this.pageNo = page;
      //调用查询方法
      this.search(page, this.pageSize);
    },
    // 序号计算
    indexMethod (index) {
    // index默认在0开始，这里+1
      return index + 1 + (this.pageNo - 1) * this.pageSize
    },
    // 获取当前日期
    filterTime() {
      var date = new Date();
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? '0' + m : m;
      var d = date.getDate();
      d = d < 10 ? '0' + d : d;
      this.currentTime = y + '-' + m + '-' + d;
    },
  }
}
</script>

<style lang="scss" scoped>
// 标题
.mytitle {
  font-size: large;
  padding-left: 10px;
  margin-bottom: 16px;
  float: left;
}

//按钮组
.myButtons {
  float: right
}

//格子的样式
.bg-white {
  background: #ffffff;
}

.grid-content {
  padding: 10px;
  margin-bottom: 10px;
  border-radius: 4px;
}

.calendar ::v-deep .el-button-group::before {
  display: none;
}

.calendar ::v-deep .el-button-group::after {
  display: none;
}

// 分割线样式
.el-divider--horizontal {
  display: block;
  height: 2px;
  width: 100%;
  margin: 24px 0;
}

// 表单各项的样式
.el-form-item {
  margin: 15px 10px 15px 10px;
}

//表单禁用字体样式
.el-input.is-disabled ::v-deep .el-input__inner {
    color: #606266;
  }
//对话框宽度
// .customWidth{
//         width:80%;
//     }
::v-deep .saveAsDialog1 {
  width: 60% !important;
}
::v-deep .saveAsDialog2 {
  width: 21% !important;
}
//日期选择框宽度
.el-date-editor.el-input, .el-date-editor.el-input__inner { width: 200px; }

.el-input {
  width: 200px;
}
</style>